<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=1200, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="#">
        <input type="text" id="userName" />
    </form>
    <script>
        const oUserName = document.querySelector('#userName');

        oUserName.addEventListener('focus', () => {
            oUserName.style.backgroundColor = 'red';
        })

        oUserName.addEventListener('blur',() => {
            oUserName.style.backgroundColor = 'white';
        })


    </script>
</body>
</html>